<template>
  <Row class="data-dictionary" style="position: relative;">
    <Col span="4" class="col-height100" style="position: relative;" v-if="leftShow">
      <p>
        <Input
          suffix="ios-search"
          placeholder="请输入名称进行搜索"
          style="width: auto"
          v-model.trim="searchParams.riskName"
          @on-change="searchChangeBtn"
          clearable
        />
      </p>
      <div class="treeAuto">
        <!-- <span style="padding-left: 10px"><Icon type="ios-arrow-down" /> <span>标准WBS</span></span>-->
        <Tree
          :data="treeList"
          ref="Tree"
          style="padding-left:10px"
          @on-select-change="checkWbBtn"
        ></Tree>
      </div>
      <img src="../../../assets/images/left.png" @click="leftShowBtn" class="imgShow"  alt="">
    </Col>
    <img src="../../../assets/images/right.png" v-if="!leftShow" @click="leftShowBtn" class="imgShow_1"  alt="">
    <Col :span="spanWidth" class="col-main">
      <Form label-position="top">
        <Row>
          <Col span="15">
            <Row>
              <Col span="8">
                <FormItem label="" style="margin-bottom: 14px;">
                  <Select
                    v-model="searchParams.riskCategoryId"
                    style="width: 90%;"
                    clearable
                    placeholder="请选择风险类别"
                  >
                    <Option
                      v-for="item in list"
                      :value="item.id"
                      :key="item.id"
                    >{{ item.riskCategoryName }}</Option
                    >
                  </Select>
                </FormItem>
              </Col>
              <Col span="8">
                <FormItem label="" style="margin-bottom: 14px;">
                  <Input style="width: auto;" v-model.trim="searchParams.name" placeholder="请输入风险作业" clearable/>
                </FormItem>
              </Col>
              <Col span="8">
                <FormItem label="" style="margin-bottom: 14px;">
                  <Input style="width: auto;" v-model.trim="searchParams.controlMeasures" placeholder="请输入管控措施" clearable/>
                </FormItem>
              </Col>
            </Row>
          </Col>
          <Col span="9" style="text-align: right;">
            <div class="button-s">
              <Button type="primary" style="margin-right: 15px" @click="searchBtn" v-if="searchBtnShow">查询</Button>
              <!--<Button type="warning" @click="resetBtn">重置</Button>-->
            </div>
          </Col>
        </Row>
      </Form>
      <div class="button-s">
        <Button type="primary" v-if="(isShow.isRiskOperation || isShow.type ===1) && addBtnShow && isDispatch && personType===1" @click="addBtn('add', '1', '措施方案新增')">新增</Button>
        <Button type="primary" v-if="(isShow.isRiskOperation || isShow.type ===1) && importBtnShow && isDispatch && personType===1" @click="addBtn('import', '1', '措施方案导入')"
        >导入</Button
        >
        <Button type="primary" @click="deleteBtn" v-if="deleteBtnShow_s && isDispatch && personType===1">删除</Button>
      </div>
      <Card style="margin-bottom: 10px;" dis-hover>
        <Row style="margin-bottom: 10px">
          <Col span="12" v-if="dataDetail && istrue">作业风险 : {{searchParams.nameType.name}}</Col>
          <Col span="12" v-if="!dataDetail && searchParams.nameType.parentId !='0' && istrue">风险类型 : {{searchParams.nameType.name}}</Col>
          <Col span="12" v-if="!dataDetail && searchParams.nameType.parentId =='0' && istrue">{{searchParams.nameType.name}}</Col>
          <Col span="12" v-if="dataDetail && istrue">作业分级 : {{dataDetail.riskLevel?dataDetail.riskLevel:"无"}}</Col>
        </Row>
        <Row style="margin-bottom: 10px">
          <Col span="12" v-if="dataDetail && istrue">风险类别 : {{dataDetail.riskCategoryNames}}</Col>
          <Col span="12" v-if="dataDetail && istrue">分级方法 : {{dataDetail.classificationMethodName?dataDetail.classificationMethodName:"无"}}</Col>
        </Row>
        <Row >
          <Col span="4">方案总数 : {{count.total}}</Col>
          <Col span="4">Ⅰ级类型 : {{count.count_1}}</Col>
          <Col span="4">Ⅱ级类型 : {{count.count_2}}</Col>
          <Col span="4">Ⅲ级类型 : {{count.count_3}}</Col>
          <Col span="4">Ⅳ级类型 : {{count.count_4}}</Col>
        </Row>
      </Card>
      <Tabs value="1" @on-click="tabpaneBtn" :animated="false">
        <TabPane :label="label"  name="1">
          <Table
            border
            ref="selection"
            :columns="columns1"
            :data="dictList"
            @on-select="selectRiado"
            @on-select-all="selectRiadoAll"
            @on-select-cancel="selectCancel"
            @on-select-all-cancel="selectAllCancel"
          >
            <template slot-scope="{ row, index }" slot="action">
              <span
                title="编辑"
                class="button-class"
                type="text"
                v-if="editoBtnShow  && isDispatch && personType===1"
                @click="addBtn('editor', row.id, '措施方案编辑', row.measureType)"
              >编辑</span
              >
              <span
                title="详情"
                class="button-class"
                type="text"
                v-if="detailBtnShow"
                @click="addBtn('details', row.id, '措施方案详情', row.code)"
              >详情</span
              >
              <span
                title="删除"
                class="button-class"
                type="text"
                v-if="deleteBtnShow  && isDispatch && personType===1"
                @click="oneDeleteBtn(row)">删除</span>
            </template>
          </Table>
        </TabPane>
        <TabPane :label="label1" name="2">
          <Table
            border
            ref="selection"
            :columns="columns2"
            :data="dictList"
            @on-select="selectRiado"
            @on-select-all="selectRiadoAll"
            @on-select-cancel="selectCancel"
            @on-select-all-cancel="selectAllCancel"
          >
            <template slot-scope="{ row, index }" slot="action">
              <span
                title="编辑"
                class="button-class"
                type="text"
                v-if="editoBtnShow  && isDispatch && personType===1"
                @click="addBtn('editor', row.id, '措施方案编辑', row.measureType)"
              >编辑</span
              >
              <span
                title="详情"
                class="button-class"
                type="text"
                v-if="detailBtnShow"
                @click="addBtn('details', row.id, '措施方案详情', row.code)"
              >详情</span
              >
              <span
                title="删除"
                class="button-class"
                type="text"
                v-if="deleteBtnShow  && isDispatch && personType===1"
                @click="oneDeleteBtn(row)">删除</span>
            </template>
          </Table>
        </TabPane>
        <TabPane :label="label2" name="3">
          <Table
            border
            ref="selection"
            :columns="columns3"
            :data="dictList"
            @on-select="selectRiado"
            @on-select-all="selectRiadoAll"
            @on-select-cancel="selectCancel"
            @on-select-all-cancel="selectAllCancel"
          >
            <template slot-scope="{ row, index }" slot="action">
              <span
                title="编辑"
                class="button-class"
                type="text"
                v-if="detailBtnShow && isDispatch && personType===1"
                @click="addBtn('editor', row.id, '措施方案编辑', row.measureType)"
              >编辑</span
              >
              <span
                title="详情"
                class="button-class"
                type="text"
                v-if="detailBtnShow"
                @click="addBtn('details', row.id, '措施方案详情', row.code)"
              >详情</span
              >
              <span
                title="删除"
                class="button-class"
                type="text"
                v-if="deleteBtnShow && isDispatch && personType===1"
                @click="oneDeleteBtn(row)">删除</span>
            </template>
          </Table>
        </TabPane>
        <TabPane :label="label3" name="4">
          <Table
            border
            ref="selection"
            :columns="columns4"
            :data="dictList"
            @on-select="selectRiado"
            @on-select-all="selectRiadoAll"
            @on-select-cancel="selectCancel"
            @on-select-all-cancel="selectAllCancel"
          >
            <template slot-scope="{ row, index }" slot="action">
              <span
                title="编辑"
                class="button-class"
                type="text"
                v-if="editoBtnShow && isDispatch && personType===1"
                @click="addBtn('editor', row.id, '措施方案编辑', row.measureType)"
              >编辑</span
              >
              <span
                title="详情"
                class="button-class"
                type="text"
                v-if="detailBtnShow"
                @click="addBtn('details', row.id, '措施方案详情')"
              >详情</span
              >
              <span
                title="删除"
                class="button-class"
                type="text"
                v-if="deleteBtnShow && isDispatch && personType===1"
                @click="oneDeleteBtn(row)">删除</span>
            </template>
          </Table>
        </TabPane>
      </Tabs>
      <Page
        class="pagination"
        :page-size-opts="[10,20,50,100]"
        :total="page.total"
        :current="page.current"
        :page-size="page.pageSize"
        @on-change="pageChange"
        @on-page-size-change="sizeChange"
        show-elevator
        show-sizer
        show-total
      />
    </Col>
    <!--导入-->
    <Modal v-model="modalImport" :mask-closable="false" title="导入">
      <Form
        ref="formData"
        :model="formData"
        label-position="top"
        :show-message="false"
      >
        <FormItem
          label="下载文件（为提高导入的成功率，请下载并使用系统提供的模板)"
          prop="name"
        >
          <Button type="primary" @click="downMb">下载模板</Button>
        </FormItem>
        <FormItem label="上传文件（仅支持xlsx,xls,文件大小<5M)" prop="name">
          <Poptip trigger="focus">
            <Upload
              action
              :show-upload-list="false"
              :before-upload="handleUpload"
            >
              <Input
                v-model="formData.fileName"
                prefix="ios-cloud-upload-outline"
                placeholder="上传文件"
                style="width: 200px"
                readonly
              />
              <Button type="primary" style="margin-left:20px;">选择文件</Button>
            </Upload>
          </Poptip>
        </FormItem>
      </Form>
      <div slot="footer">
        <Button type="primary" size="large" :loading="loading" @click="saveImport()"
        >
          <span v-if="!loading">开始导入</span>
          <span v-else>正在导入中...</span>
        </Button>
      </div>
    </Modal>
    <!--修改后导入-->
    <Modal
      v-model="modalUpdateImport"
      :mask-closable="false"
      title="下面数据有误,导入未成功,请修改后[继续导入]:"
      width="95%"
    >
      <Table
        :columns="columns5"
        :data="updateImportList"
        border
        ref="selection"
      >
        <template slot-scope="{ row, index }" slot="select1">
          <Select
            class="width50"
            transfer
            v-model="row.riskLevel"
            @on-change="changeBtn(1, row, index)"
            placeholder="请选择风险等级"
          >
            <Option
              v-for="item in riskLevelList"
              :value="item.id"
              :key="item.id"
            >{{ item.name }}</Option
            >
          </Select>
        </template>
        <template slot-scope="{ row, index }" slot="select2">
          <Select
            class="width50"
            transfer
            v-model="row.frequencyName"
            @on-change="changeBtn(2, row, index)"
            placeholder="请选择频次"
          >
            <Option
              v-for="item in frequencyList"
              :value="item.frequencyName"
              :key="item.id"
            >{{ item.frequencyName }}</Option
            >
          </Select>
        </template>
      </Table>
      <div slot="footer">
        <Button type="text" size="large" @click="elseBtn"
        >忽略</Button
        >
        <Button type="primary" size="large" :loading="loading" @click="saveImport2()">
          <span v-if="!loading">修改后提交</span>
          <span v-else>正在提交中...</span>
        </Button>
      </div>
    </Modal>
  </Row>
</template>

<script>
  import apiUrl from "@/api/base";
  export default {
    name: 'measures-library',
    data() {
      return {
        leftShow:true,
        spanWidth:20,
        loading:false,
        isDispatch: false,//是否为调度港
        personType:JSON.parse(localStorage.getItem('personType')),
        istrue:true,
        modalImport: false,
        modalUpdateImport: false,
        addBtnShow:false,
        editoBtnShow:false,
        deleteBtnShow:false,
        deleteBtnShow_s:false,
        importBtnShow:false,
        detailBtnShow:false,
        searchBtnShow:false,
        treeList:[],
        searchParams: {
          riskCategoryId: '',
          name:'',
          controlMeasures:'',
          measureType:1,
          riskLevel:'',
          riskOperationId:'',
          riskName:'',
          nameType:{
            parentId:'0',
            name:'管理措施'
          }
        },
        formData: {
          fileName: '',
          file: null
        },
        riskLevelList:[
          {id:'1',name:'一级'},
          {id:'2',name:'二级'},
          {id:'3',name:'三级'},
          {id:'4',name:'四级'},
        ],
        frequencyList:[],
        updateImportList: [],
        columns5: [
          /*{
              type: "selection",
              width: 60,
              align: "center",
            },*/
          {
            title: "序号",
            type: "index",
            align: "center",
            width: 70
          },
          {
            title: '*管控措施',
            key: 'controlMeasures',
            align: 'center',
            render: (h, params) => {
              var vm = this
              return h('Input', {
                props: {
                  value: params.row.controlMeasures,
                  maxlength:300
                },
                attrs: {
                  title: params.row.controlMeasures
                },
                on: {
                  'on-change'(event) {
                    params.row.controlMeasures = event.target.value
                    vm.updateImportList[params.index] = params.row
                  }
                }
              })
            }
          },
          {
            title: '*作业风险等级',
            key: 'riskLevel',
            align: 'center',
            slot: 'select1'
          },
          {
            title: '*项目部管控部门',
            key: 'projectManagementDepartment',
            align: 'center',
            render: (h, params) => {
              var vm = this
              return h('Input', {
                props: {
                  maxlength:20,
                  value: params.row.projectManagementDepartment,
                  disabled:!(params.row.riskLevel=='1' || params.row.riskLevel=='2' || params.row.riskLevel=='3' || params.row.riskLevel=='4')
                },
                attrs: {
                  title: params.row.projectManagementDepartment
                },
                on: {
                  'on-change'(event) {
                    params.row.projectManagementDepartment = event.target.value
                    vm.updateImportList[params.index] = params.row
                  }
                }
              })
            }
          },
          {
            title: '*项目部分管领导',
            key: 'projectManagementLeader',
            align: 'center',
            render: (h, params) => {
              var vm = this
              return h('Input', {
                props: {
                  maxlength:20,
                  value: params.row.projectManagementLeader,
                  disabled:!(params.row.riskLevel=='1' || params.row.riskLevel=='2' || params.row.riskLevel=='3' || params.row.riskLevel=='4')
                },
                attrs: {
                  title: params.row.projectManagementLeader
                },
                on: {
                  'on-change'(event) {
                    params.row.projectManagementLeader = event.target.value
                    vm.updateImportList[params.index] = params.row
                  }
                }
              })
            }
          },
          {
            title: '*项目部主管领导',
            key: 'leaderInChargeOfProjectDepartment',
            align: 'center',
            render: (h, params) => {
              var vm = this
              return h('Input', {
                props: {
                  maxlength:20,
                  value: params.row.leaderInChargeOfProjectDepartment,
                  disabled:!(params.row.riskLevel=='1' || params.row.riskLevel=='2' || params.row.riskLevel=='3' || params.row.riskLevel=='4')
                },
                attrs: {
                  title: params.row.leaderInChargeOfProjectDepartment
                },
                on: {
                  'on-change'(event) {
                    params.row.leaderInChargeOfProjectDepartment = event.target.value
                    vm.updateImportList[params.index] = params.row
                  }
                }
              })
            }
          },
          {
            title: '*工程公司管控部门',
            key: 'controlDepartmentOfEngineeringCompany',
            align: 'center',
            render: (h, params) => {
              var vm = this
              return h('Input', {
                props: {
                  maxlength:20,
                  value: params.row.controlDepartmentOfEngineeringCompany,
                  disabled:!(params.row.riskLevel=='1' || params.row.riskLevel=='2' || params.row.riskLevel=='3')
                },
                attrs: {
                  title: params.row.controlDepartmentOfEngineeringCompany
                },
                on: {
                  'on-change'(event) {
                    params.row.controlDepartmentOfEngineeringCompany = event.target.value
                    vm.updateImportList[params.index] = params.row
                  }
                }
              })
            }
          },
          {
            title: '*工程公司分管领导',
            key: 'leaderInChargeOfEngineeringCompany',
            align: 'center',
            render: (h, params) => {
              var vm = this
              return h('Input', {
                props: {
                  maxlength:20,
                  value: params.row.leaderInChargeOfEngineeringCompany,
                  disabled:!(params.row.riskLevel=='1' || params.row.riskLevel=='2' || params.row.riskLevel=='3')
                },
                attrs: {
                  title: params.row.leaderInChargeOfEngineeringCompany
                },
                on: {
                  'on-change'(event) {
                    params.row.leaderInChargeOfEngineeringCompany = event.target.value
                    vm.updateImportList[params.index] = params.row
                  }
                }
              })
            }
          },
          {
            title: '*集团公司管控部门',
            key: 'groupCompanyControlDepartment',
            align: 'center',
            render: (h, params) => {
              var vm = this
              return h('Input', {
                props: {
                  maxlength:20,
                  value: params.row.groupCompanyControlDepartment,
                  disabled:!(params.row.riskLevel=='1' || params.row.riskLevel=='2')
                },
                attrs: {
                  title: params.row.groupCompanyControlDepartment
                },
                on: {
                  'on-change'(event) {
                    params.row.groupCompanyControlDepartment = event.target.value
                    vm.updateImportList[params.index] = params.row
                  }
                }
              })
            }
          },
          {
            title: '*集团公司分管领导',
            key: 'leaderInChargeOfGroupCompany',
            align: 'center',
            render: (h, params) => {
              var vm = this
              return h('Input', {
                props: {
                  maxlength:20,
                  value: params.row.leaderInChargeOfGroupCompany,
                  disabled:!(params.row.riskLevel=='1' || params.row.riskLevel=='2')
                },
                attrs: {
                  title: params.row.leaderInChargeOfGroupCompany
                },
                on: {
                  'on-change'(event) {
                    params.row.leaderInChargeOfGroupCompany = event.target.value
                    vm.updateImportList[params.index] = params.row
                  }
                }
              })
            }
          },
          {
            title: '频次',
            key: 'frequencyName',
            align: 'center',
            slot: 'select2'
          },
          {
            title: '失败原因',
            key: 'errorMsg',
            align: 'center',
            render: (h, params) => {
              return h('span',{
                style:{
                  color:"#f00"
                }
              },params.row.errorMsg)
            }
          }
        ],
        isShow:{
          isRiskOperation:false,
          type:1,
        },
        count:{},
        dataDetail:'',
        list: [], //工程类型SELECT选择
        list1: [], //专业类型SELECT选择
        engineeringTypeList: [],
        wbsList: [], //专业类型
        parentId: '0',
        deleteList: [],
        columns1: [
          {
            type: 'selection',
            width: 60,
            align: 'center',
            fixed: 'left'
          },
          {
            title: '序号',
            align: 'center',
            width: 70,
            fixed: 'left',
            render: (h, params) => {
              return h(
                'span',
                params.index + (this.page.current - 1) * this.page.pageSize + 1
              )
            }
          },
          {
            title: '管控措施',
            key: 'controlMeasures',
            align: 'center',
            tooltip:true,
            minWidth: 300
          },
          {
            title: '项目部管控部门',
            key: 'projectManagementDepartment',
            align: 'center',
            minWidth: 150
          },
          {
            title: '项目部分管领导',
            key: 'projectManagementLeader',
            align: 'center',
            minWidth: 150
          },
          {
            title: '项目部主管领导',
            key: 'leaderInChargeOfProjectDepartment',
            align: 'center',
            minWidth: 150
          },
          {
            title: '工程公司管控部门',
            key: 'controlDepartmentOfEngineeringCompany',
            align: 'center',
            minWidth: 150
          },
          {
            title: '工程公司分管领导',
            key: 'leaderInChargeOfEngineeringCompany',
            align: 'center',
            minWidth: 150
          },
          {
            title: '集团公司管控部门',
            key: 'groupCompanyControlDepartment',
            align: 'center',
            minWidth: 150
          },
          {
            title: '集团公司分管领导',
            key: 'leaderInChargeOfGroupCompany',
            align: 'center',
            minWidth: 150
          },
          {
            title: '操作',
            minWidth: 180,
            align: 'center',
            slot: 'action',
            fixed: 'right'
          }
        ],
        columns2: [
          {
            type: 'selection',
            width: 60,
            align: 'center',
            fixed: 'left'
          },
          {
            title: '序号',
            align: 'center',
            width: 70,
            fixed: 'left',
            render: (h, params) => {
              return h(
                'span',
                params.index + (this.page.current - 1) * this.page.pageSize + 1
              )
            }
          },
          {
            title: '管控措施',
            key: 'controlMeasures',
            align: 'center',
            tooltip:true,
            minWidth: 300
          },
          {
            title: '项目部管控部门',
            key: 'projectManagementDepartment',
            align: 'center',
            minWidth: 150
          },
          {
            title: '项目部分管领导',
            key: 'projectManagementLeader',
            align: 'center',
            minWidth: 150
          },
          {
            title: '项目部主管领导',
            key: 'leaderInChargeOfProjectDepartment',
            align: 'center',
            minWidth: 150
          },
          {
            title: '工程公司管控部门',
            key: 'controlDepartmentOfEngineeringCompany',
            align: 'center',
            minWidth: 150
          },
          {
            title: '工程公司分管领导',
            key: 'leaderInChargeOfEngineeringCompany',
            align: 'center',
            minWidth: 150
          },
          {
            title: '集团公司管控部门',
            key: 'groupCompanyControlDepartment',
            align: 'center',
            minWidth: 150
          },
          {
            title: '集团公司分管领导',
            key: 'leaderInChargeOfGroupCompany',
            align: 'center',
            minWidth: 150
          },
          {
            title: '操作',
            minWidth: 180,
            align: 'center',
            slot: 'action',
            fixed: 'right'
          }
        ],
        columns3: [
          {
            type: 'selection',
            width: 60,
            align: 'center',
            fixed: 'left'
          },
          {
            title: '序号',
            align: 'center',
            width: 70,
            fixed: 'left',
            render: (h, params) => {
              return h(
                'span',
                params.index + (this.page.current - 1) * this.page.pageSize + 1
              )
            }
          },
          {
            title: '管控措施',
            key: 'controlMeasures',
            align: 'center',
            tooltip:true,
            minWidth: 300
          },
          {
            title: '项目部管控部门',
            key: 'projectManagementDepartment',
            align: 'center',
            minWidth: 150
          },
          {
            title: '项目部分管领导',
            key: 'projectManagementLeader',
            align: 'center',
            minWidth: 150
          },
          {
            title: '项目部主管领导',
            key: 'leaderInChargeOfProjectDepartment',
            align: 'center',
            minWidth: 150
          },
          {
            title: '工程公司管控部门',
            key: 'controlDepartmentOfEngineeringCompany',
            align: 'center',
            minWidth: 150
          },
          {
            title: '工程公司分管领导',
            key: 'leaderInChargeOfEngineeringCompany',
            align: 'center',
            minWidth: 150
          },
          {
            title: '操作',
            minWidth: 180,
            align: 'center',
            slot: 'action',
            fixed: 'right'
          }
        ],
        columns4: [
          {
            type: 'selection',
            width: 60,
            align: 'center',
          },
          {
            title: '序号',
            align: 'center',
            width: 70,
            render: (h, params) => {
              return h(
                'span',
                params.index + (this.page.current - 1) * this.page.pageSize + 1
              )
            }
          },
          {
            title: '管控措施',
            key: 'controlMeasures',
            align: 'center',
            tooltip:true,
            minWidth: 300
          },
          {
            title: '项目部管控部门',
            key: 'projectManagementDepartment',
            align: 'center',
          },
          {
            title: '项目部分管领导',
            key: 'projectManagementLeader',
            align: 'center',
          },
          {
            title: '项目部主管领导',
            key: 'leaderInChargeOfProjectDepartment',
            align: 'center',
          },
          {
            title: '操作',
            minWidth: 180,
            align: 'center',
            slot: 'action',
          }
        ],
        dictList: [],
        typeList: [],
        page: {
          total: 0,
          current: 1,
          pageSize: 10,
          totalPage: 0
        },
        label: h => {
          return h('div', [
            h(
              'span',
              {
                style: {
                  color: '#EF3E43'
                }
              },
              'Ⅰ级风险'
            )
          ])
        },
        label1: h => {
          return h(
            'span',
            {
              style: {
                color: '#F86A30'
              }
            },
            'Ⅱ级风险'
          )
        },
        label2: h => {
          return h(
            'span',
            {
              style: {
                color: '#F3CF34'
              }
            },
            'Ⅲ级风险'
          )
        },
        label3: h => {
          return h(
            'span',
            {
              style: {
                color: '#3D6FC9'
              }
            },
            'Ⅳ级风险'
          )
        }
      }
    },
    methods: {
      //查询当前用户是否为调度员
      checkPerson(){
        this.$api.measurePlan.checkDispatch().then(res => {
          if(res.code === 200){
            this.isDispatch = true;
          } else {
            this.isDispatch = false;
          }
        })
      },
      addBtn(type, id, name, measureType) {
        if (type === 'import') {
          this.modalImport = true;
          this.formData= {
            fileName: '',
            file: null
          };
        } else if(type === 'add'){
          this.$router.push({
            name:'measures-library-add',
            params:{type,id,name,measureType:this.searchParams.measureType,riskOperationId:this.parentId,}
          })
        }else if(type === 'editor'){
          this.$router.push({
            name:'measures-library-edit',
            params:{type,id,name},
            query: {
              measureType: measureType,
              riskOperationId: this.parentId,
            }
          })
        }else if(type === 'details'){
          this.$router.push({
            name:'measures-library-detail',
            params:{type,id,name},
            query: {
              measureType: this.searchParams.measureType,
              riskOperationId: this.parentId,
            }
          })
        }
      },
      //单个删除
      oneDeleteBtn(row){
        this.$Modal.confirm({
          title: '温馨提示',
          closable: true,
          content: '确认删除吗？',
          width: 360,
          onOk:() => {
            this.$api.measuresLibrary.getmeasuresLibraryDelete(row.id).then(res => {
              if(res.code === 200){
                this.$Message.success(res.message);
                this.getWbsTabelList();
              }else {
                this.$Message.warning(res.message)
              }
            })
          }
        })
      },
      //批量删除
      deleteBtn() {
        if (this.deleteList.length <= 0) {
          this.$Message.warning('请选择要删除的数据')
          return false
        }
        const deleteList = []
        this.deleteList.forEach(val => {
          deleteList.push(val.id)
        })
        this.$Modal.confirm({
          title: '温馨提示',
          closable: true,
          content: '确认删除吗？',
          width: 360,
          onOk: () => {
            this.$api.measuresLibrary
              .getmeasuresLibrarybatchDelete(deleteList)
              .then(res => {
                if (res.code === 200) {
                  this.deleteList = [];
                  this.$Message.success(res.message);
                  this.getWbsTabelList();
                } else {
                  this.$Message.error(res.data.msg)
                }
              })
          }
        })
      },
      tabpaneBtn(e){
        this.page.current =1;
        this.page.currentPage =10;
        this.searchParams.riskLevel = e;
        this.getWbsTabelList();
      },
      searchChangeBtn(){
        this.searchParams.riskCategoryId = '';
        this.searchParams.name = '';
        this.searchParams.controlMeasures = '';
        this.getriskInfoLibqueryRiskTree(1);//1 代表的是 搜索 需要全部展开
      },
      //树f
      getriskInfoLibqueryRiskTree(type) {
        this.$api.measuresLibrary.getriskInfoLibqueryRiskTree(this.searchParams.riskName).then(res => {
          if (res.code === 200) {
            this.treeList = this.getInfoTree(res.data,type);
            let name = "管理措施";
            if(this.searchParams.riskName){
              if(name.indexOf(this.searchParams.riskName)>-1){
                this.treeList.unshift({"title":"管理措施","name":"管理措施","type":1,"parentId":'0',"id":'0'});
                this.treeList[1].expand = true;
              }else {
                if(this.treeList.length>0){
                  this.treeList[0].expand = true;
                }
              }
            }else {
              this.treeList.unshift({"title":"管理措施","name":"管理措施","type":1,"parentId":'0',"id":'0'});
              this.treeList[1].expand = true;
            }
          } else {
            this.$Message.error(res.data.msg)
          }
        })
      },
      getInfoTree(list,type){
        return list.map(item => {
          this.$set(item, 'title', item.name)
          this.$set(item, 'expand', false)
          if(type ===1 && this.searchParams.riskName){
            this.$set(item, 'expand', true)
          }
          this.$set(item, 'type', 2)
          if(item.children.length>0){
            this.getInfoTree(item.children,type);
          }
          return item;
        })
      },
      //风险类别
      getRiskCategoryFindAll() {
        this.$api.measuresLibrary.getRiskCategoryFindAll().then(res => {
          if (res.code === 200) {
            this.list = res.data
          } else {
            this.$Message.error(res.message)
          }
        })
      },
      //频次
      getFrequencyList() {
        this.$api.measuresLibrary.getFrequencyList().then(res => {
          if (res.code === 200) {
            this.frequencyList = res.data;
          } else {
            this.$Message.error(res.message)
          }
        })
      },
      checkWbBtn(a, b) {//点击树
        console.log(a, b);
        this.istrue = true;
        this.isShow.isRiskOperation = b.isRiskOperation;
        this.isShow.type = b.type;
        this.dataDetail = '';
        this.parentId = b.id;
        this.page.current = 1;
        this.page.pageSize = 10;
        this.searchParams.measureType = b.type;
        this.searchParams.riskOperationId = b.id;
        this.searchParams.nameType = b;
        this.searchParams.name = '';
        this.searchParams.controlMeasures = '';
        this.searchParams.riskCategoryId = '';
        this.getWbsTabelList();
        if(b.isRiskOperation)
          this.getDetail(this.parentId);
      },
      //导入
      downMb() {
        // 下载模板
        window.open('http://211.159.175.34/model/管控措施导入模板.xlsx')
      },
      handleUpload(file) {
        this.formData.file = file
        this.formData.fileName = file.name
        return false
      },
      saveImport() {
        if (this.formData.file != null) {
          let type = this.formData.file.name.slice(this.formData.file.name.lastIndexOf("."));
          let size = this.formData.file.size / 1024 / 1024;
          if(size > 5){
            this.$Message.warning("文件不能大于5M");
            return
          }
          let formData = new FormData()
          formData.append('file', this.formData.file)
          formData.append('measureType', this.searchParams.measureType)
          formData.append('riskId', this.searchParams.riskOperationId)
          if(type === '.xlsx' || type === '.xls'){
            this.loading = true;
            this.$api.measuresLibrary
              .getmeasuresLibraryimportExcel(formData)
              .then(res => {
                if (res.code == 200) {
                  this.formData.file = null
                  this.modalImport = false
                  this.loading = false;
                  this.$Message.success(res.message)
                  this.getWbsTabelList()
                } else if (res.code === 201) {
                  this.$Message.warning(res.message)
                  this.modalUpdateImport = true
                  this.updateImportList = res.data;
                  this.loading = false;
                } else {
                  this.loading = false;
                  this.$Message.warning(res.message)
                }
              })
          }else {
            this.$Message.warning('请上传指定的格式');
          }
        } else {
          this.$Message.warning('请选择要上传的文件')
        }
      },
      saveImport2() {
        this.updateImportList.forEach(item => {
          if (Array.isArray(item.riskLevel))
            item.riskLevel = item.riskLevel.toString()
        })
        this.loading = true;
        this.$api.measuresLibrary
          .getmeasuresLibraryupdateImport(this.updateImportList)
          .then(res => {
            if (res.code == 200) {
              this.loading = false;
              this.formData.file = null
              this.modalImport = false
              this.modalUpdateImport = false
              this.$Message.success(res.message)
              this.getWbsTabelList()
            } else if (res.code === 201) {
              this.loading = false;
              this.$Message.warning(res.message)
              this.modalUpdateImport = true
              this.updateImportList = res.data
            } else {
              this.loading = false;
              this.$Message.warning(res.message)
            }
          })
      },
      elseBtn(){
        this.modalUpdateImport = false;
        this.modalImport = false;
        this.getWbsTabelList()
      },
      changeBtn(type, row, num) {
        //console.log(row,index);
        this.updateImportList.map((item, index) => {
          if (index === num)
            if (type === 1) {
              item.riskLevel = row.riskLevel
            } else if (type === 2) {
              item.frequencyName = row.frequencyName
            }
        })
      },
      //列表
      getWbsTabelList() {
        let prames = {
          currentPage: this.page.current,
          pageSize: this.page.pageSize,
          whereMap: {
            "measureType": this.searchParams.measureType,//"措施类型（1：管理，2：技术），不传值的话默认查询”管理措施“类型",
            "riskLevel": this.searchParams.riskLevel,//"风险作业等级（1：Ⅰ级，2：Ⅱ级，3：Ⅲ级，4：Ⅳ级），不传值的话默认查询”Ⅰ级“类型",
            "riskOperationId": this.searchParams.riskOperationId,//"风险信息ID，如果查询所有的技术措施类型，此值可以不填写",
            "riskCategoryId": this.searchParams.riskCategoryId,//"风险作业类别",
            "name": this.searchParams.name,//"风险作业名称",
            "controlMeasures": this.searchParams.controlMeasures,//"管控措施"
            "riskName":this.searchParams.riskName
          }
        }
        this.$api.measuresLibrary.getmeasuresLibrarypageList(prames).then(res => {
          if (res.code == 200) {
            this.dictList = res.data.resultObject
            this.page.total = res.data.totalRecord
            this.page.totalPage = res.data.totalPage
            this.getmeasuresLibrarylistStatistics();
          } else {
            this.$Message.error(res.data.msg)
          }
        })
      },
      //措施方案汇总
      getmeasuresLibrarylistStatistics() {
        let res = {
          "measureType": this.searchParams.measureType,//"措施类型（1：管理，2：技术），不传值的话默认查询”管理措施“类型",
          "riskLevel": this.searchParams.riskLevel,//"风险作业等级（1：Ⅰ级，2：Ⅱ级，3：Ⅲ级，4：Ⅳ级），不传值的话默认查询”Ⅰ级“类型",
          "riskOperationId": this.searchParams.riskOperationId,//"风险信息ID，如果查询所有的技术措施类型，此值可以不填写",
          "riskCategoryId": this.searchParams.riskCategoryId,//"风险作业类别",
          "name": this.searchParams.name,//"风险作业名称",
          "controlMeasures": this.searchParams.controlMeasures,//"管控措施"
          "riskName":this.searchParams.riskName
        }
        this.$api.measuresLibrary.getmeasuresLibrarylistStatistics(res).then(res => {
          if (res.code == 200) {
            this.count = res.data;
          } else {
            this.$Message.error(res.data.msg)
          }
        })
      },
      //风险信息详情
      getDetail(id){
        this.$api.measuresLibrary.getriskInfoLibdetails(id).then((res) => {
          if (res.code === 200) {
            this.dataDetail = res.data;
            if(this.dataDetail){
              if(this.dataDetail.riskLevel == 1){
                this.dataDetail.riskLevel = "一级"
              }else if(this.dataDetail.riskLevel == 2){
                this.dataDetail.riskLevel = "二级"
              }else if(this.dataDetail.riskLevel == 3){
                this.dataDetail.riskLevel = "三级"
              }else if(this.dataDetail.riskLevel == 4){
                this.dataDetail.riskLevel = "四级"
              }
            }
          } else {
            this.$Message.error(res.message);
          }
        })
      },
      //按钮显示
      buttonShow() {
        let buttonList = JSON.parse(localStorage.getItem('buttonList'))
        buttonList.map(val => {
          let key = Object.keys(val).toString();
          if (key === this.$route.name) {
            Object.values(val)[0].map(item => {
              if (item.code === 'P_0602_01') {
                this.addBtnShow = true
              } else if (item.code === 'P_0602_05') {
                this.editoBtnShow = true
              } else if (item.code === 'P_0602_07') {
                this.deleteBtnShow = true
              }else if (item.code === 'P_0602_03') {
                this.deleteBtnShow_s = true
              }else if (item.code === 'P_0602_02') {
                this.importBtnShow = true
              }else if (item.code === 'P_0602_06') {
                this.detailBtnShow = true
              }else if (item.code === 'P_0602_04') {
                this.searchBtnShow = true
              }
            })
          }
        })
      },
      leftShowBtn(){
        this.leftShow = !this.leftShow ;
        this.leftShow?this.spanWidth=20:this.spanWidth=24;
      },
      //搜索
      searchBtn() {
        this.isShow.type =0;
        this.isShow.isRiskOperation =false;
        this.istrue = false;
        this.searchParams.riskOperationId = '';
        this.searchParams.riskName = '';
        this.searchParams.measureType = '0';
        this.getWbsTabelList();
        this.getriskInfoLibqueryRiskTree();
      },
      //重置
      resetBtn() {
        this.searchParams.riskCategoryId = ''
        this.searchParams.name = ''
        this.searchParams.controlMeasures = ''
        this.getWbsTabelList()
      },
      //全选
      selectRiadoAll(e) {
        this.deleteList = e
      },
      //全选取消
      selectAllCancel() {
        this.deleteList = []
      },
      //单选
      selectRiado(e) {
        this.deleteList = e
      },
      //取消某一项
      selectCancel(e) {
        this.deleteList.splice(e, 1)
      },
      pageChange(current) {
        this.page.current = current
        this.getWbsTabelList(this.parentId)
      },
      sizeChange(size) {
        this.page.current = 1
        this.page.pageSize = size
        this.getWbsTabelList(this.parentId)
      }
    },
    /*watch: {
      $route(to, from) {
        const fromUrl = from.path
        const toUrl = to.path
        if (fromUrl.indexOf(toUrl) > -1) {
          if (fromUrl.indexOf('add') > -1 || fromUrl.indexOf('import') > -1) {
            if (localStorage.getItem('page')) {
              this.getWbsList(this.searchParams.dictEngineeringType)
            }
          }
          if (fromUrl.indexOf('editor') > -1) {
            if (localStorage.getItem('page')) {
              let page = JSON.parse(localStorage.getItem('page'))
              this.page.current = page.current
              this.page.pageSize = page.pageSize
              this.getWbsTabelList(this.parentId)
              this.getWbsList(this.searchParams.dictEngineeringType)
            }
          }
        }
        localStorage.setItem('page', '')
      }
    },*/
    mounted() {
      this.getriskInfoLibqueryRiskTree()
      this.getRiskCategoryFindAll()
      this.getFrequencyList()
      this.getWbsTabelList()
      this.buttonShow()
      this.checkPerson()
    },
    activated() {
      this.getWbsTabelList()
    }
  }
</script>

<style lang="scss" scoped>
  .data-dictionary {
    height: calc(100% - 0px);
    .col-height100 {
      height: 100%;
      border-right: 1px solid #ebeef1;
      overflow: auto;
      p {
        padding: 10px;
      }
      .treeAuto{
        height: calc(100% - 60px);
        overflow: auto;
      }
    }
    .col-main {
      padding: 10px;
      .button-s {
        margin-bottom: 15px;
        button {
          margin-right: 15px;
        }
      }
    }
    .tabs_box {
      color: #f00 !important;
    }
    .imgShow,.imgShow_1{
      position: absolute;
      right: 0;
      top: 50%;
      cursor: pointer;
      z-index: 11;
    }
    .imgShow_1{
      left: 0;
    }
  }
</style>
